package org.pay.model;

import org.pay.PayUtils;

import java.text.SimpleDateFormat;

import java.util.Date;

public class PayReqData {

    // string Y 1024 消費者行動支付一維或二維條碼值
    private String BuyerID;

    //string Y 2 掃碼付款請填入 ‘22
    private String TxType = "22";

    //string Y 50 端末設備此筆交易之交易編號（正負交易皆不得重複）?
    private String BillNumber;

    //Y 10交易含兩位小數但不包含小數點之金額。Ex:交易 950元，應填入 95000。
    private int Amount;

    //string Y 8交易日期 (YYYYMMDD)Ex: 20211231
    private String LocalDate;

    //LocalTime string Y 6 交易時間 (hhmmss)Ex: 235959
    private String LocalTime;

    //Detail string N 999 交易品項。填入規格[“商品”]+[“小寫 x”]+[“數字”] ex：刷卡機 x1,紙捲 x20,連接線 x1
    private String Detail;

    public PayReqData(String buyerID, double amount, String detail) {
        BuyerID = buyerID;
        BillNumber = PayUtils.randomOrderCode();
        Amount =  (int) Math.floor(amount * 100);
        Detail = detail;
        SimpleDateFormat dmDate = new SimpleDateFormat("yyyyMMddHHmmss");
        Date date = new Date();
        String dateran = dmDate.format(date);
        LocalDate=dateran.substring(0,8);
        LocalTime=dateran.substring(8,14);
    }

    public PayReqData(String buyerID, String txType, String billNumber, int amount, String localDate, String localTime, String detail) {
        BuyerID = buyerID;
        TxType = txType;
        BillNumber = billNumber;
        Amount = amount;
        LocalDate = localDate;
        LocalTime = localTime;
        Detail = detail;
    }


    public String getBuyerID() {
        return BuyerID;
    }

    public void setBuyerID(String buyerID) {
        BuyerID = buyerID;
    }

    public String getTxType() {
        return TxType;
    }

    public void setTxType(String txType) {
        TxType = txType;
    }

    public String getBillNumber() {
        return BillNumber;
    }

    public void setBillNumber(String billNumber) {
        BillNumber = billNumber;
    }

    public int getAmount() {
        return Amount;
    }

    public void setAmount(int amount) {
        Amount = amount;
    }

    public String getLocalDate() {
        return LocalDate;
    }

    public void setLocalDate(String localDate) {
        LocalDate = localDate;
    }

    public String getLocalTime() {
        return LocalTime;
    }

    public void setLocalTime(String localTime) {
        LocalTime = localTime;
    }

    public String getDetail() {
        return Detail;
    }

    public void setDetail(String detail) {
        Detail = detail;
    }


    @Override
    public String toString() {
        return "PayReqData{" +
                "BuyerID='" + BuyerID + '\'' +
                ", TxType='" + TxType + '\'' +
                ", BillNumber='" + BillNumber + '\'' +
                ", Amount=" + Amount +
                ", LocalDate='" + LocalDate + '\'' +
                ", LocalTime='" + LocalTime + '\'' +
                ", Detail='" + Detail + '\'' +
                '}';
    }
}
